﻿using System;
using System.ComponentModel;
using System.Windows;

using GalaSoft.MvvmLight.Ioc;

using Stock.ViewModel;
using Stock.Core;
using Stock.Model;

namespace Stock
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow
    {
        public MainWindow()
        {
            InitializeComponent();

            var vm = SimpleIoc.Default.GetInstance<MainViewModel>();
            vm.Window = this;
            DataContext = vm;
        }

        protected override void OnContentRendered(EventArgs e)
        {
            base.OnContentRendered(e);

            string args = Application.Current.GetFirstArgs();
            if (!string.IsNullOrEmpty(args))
            {
                if (args.ToLower().Equals(AppConst.VALUE_H))
                {
                    SetShowInfo(true);
                }
            }
        }

        //protected override void OnContentRendered(EventArgs e)
        //{
        //    base.OnContentRendered(e);
        //    Hide();
        //    if (MessageBox.Ask(AppConst.TEXT_COME_FISH_MODE, AppConst.TEXT_APP_NAME) == MessageBoxResult.OK)
        //    {
        //        Close();
        //    }
        //    else
        //    {
        //        Show();
        //    }
        //}

        protected override void OnActivated(EventArgs e)
        {
            base.OnActivated(e);

            SetShowInfo(false);
        }

        protected override void OnClosing(CancelEventArgs e)
        {
            SetShowInfo(true);
            e.Cancel = true;
        }

        private void SetShowInfo(bool showInfo)
        {
            var vm = (MainViewModel)DataContext;
            vm.ShowInfo = showInfo;
        }
    }
}
